package com.qingfeng.core.dao.qingfeng;


import com.qingfeng.core.config.database.BaseMapper;
import com.qingfeng.core.dao.BaseDao;
import com.qingfeng.core.entity.qingfeng.Faq;
import com.qingfeng.core.entity.qingfeng.FaqType;
import com.qingfeng.core.mapper.qingfeng.FaqMapper;
import com.qingfeng.core.mapper.qingfeng.FaqTypeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description: FAQ
 * @author:LWY
 * @date: 2017/10/16 17:15
 * @modified:
 */

@Repository
public class FaqDao extends BaseDao<Faq> {

    @Autowired
    FaqMapper faqMapper;
    @Autowired
    FaqTypeMapper faqTypeMapper;

    @Override
    protected BaseMapper<Faq> getBaseMapper() {
        return faqMapper;
    }


    /**
     * 获取所有的FAQ
     *
     * @return key:FAQ类型名字，value:FAQ集合
     */
    public List<Map<String, Object>> get() {
        List<Map<String, Object>> list = new ArrayList<>();
        //获取所有的类型
        FaqType faqType = new FaqType();
        faqType.setState(1);
        List<FaqType> faqTypes = faqTypeMapper.select(faqType);
        for (FaqType type : faqTypes) {
            Faq faq = new Faq();
            faq.setType(type.getId());
            faq.setState(1);
            List<Faq> faqs = faqMapper.select(faq);
            Map<String, Object> map = new HashMap<>();
            map.put("faqs", faqs);
            map.put("type", type.getType_name());
            list.add(map);
        }
        return list;
    }
}
